var thisResultObj;

layui.use(['layer', 'form', 'element', 'table'], function() {
	var layer = layui.layer,
		form = layui.form,
		element = layui.element,
		table = layui.table;

	// 查询分类
	var tableArray = new Array();
	AjaxPostFn('/system/orderinfo/evaluate/select?page=1&pagesize=100', "{}", function(jsonData) {
		if(jsonData.pageInfo.size != 0) {
			$.each(jsonData.dataResultObj, function(idx, obj) {
				
				for(var i = 0; i < obj.length; i++) {
					tableArray.push({
						"id": obj[i].id,
//						<a class="layui-btn layui-btn " lay-event="Seethis" >查看并回复</a>
						"operation": '<a class="layui-btn layui-btn-danger " lay-event="delthis" >删除</a>',
						
						"evaluateId": obj[i].evaluateId,
						"commodityNumber": obj[i].commodityNumber,
						"commodityStar": obj[i].commodityStar,
						"evaluateText": obj[i].evaluateText,
						"evaluatePhoto": obj[i].evaluatePhoto,
						"updateTime": getMyDate(obj[i].updateTime),
						
					});
					console.log()
				}
				//			
			});
		};
		console.log(tableArray);

		//展示已知数据
		var tableIns = table.render({
			elem: '#cctable',
			cols: [
				[ //标题栏
					{
						type: 'numbers',
						fixed: 'left',
						title: '行号'
					}, {
						field: 'id',
						minWidth: '0%',
						width: '0%',
						type: 'space',
						style: 'display:none'
					}, {
						field: 'operation',
						width: 300,
						title: '操作',
						fixed: 'left'
					}, {
						field: 'evaluateId',
						width: 180,
						title: '评论ID'
					}, {
						field: 'commodityNumber',
						width: 180,
						title: '商品编码'
					}, {
						field: 'commodityStar',
						width: 180,
						title: '商品星级'
					}, {
						field: 'evaluateText',
						width: 180,
						title: '评价内容'
					}, {
						field: 'evaluatePhoto',
						width: 180,
						title: '评价图片'
					}, {
						field: 'updateTime',
						width: 180,
						title: '评价时间'
					},

				]
			],
			data: tableArray,
			id: 'cctableid',
			size: 'lg',
			even: true,
			page: true, //是否显示分页
			done: function(res, curr, count) {
				//图片点击放大
				TopimgFn();

			}
		});
	}); //json结束

	//监听表格内的按钮
	table.on('tool(table100)', function(obj) {
		var data = obj.data;
		if(obj.event === 'Seethis') {
			var strCont =  '';
			layer.open({
				type: 1,
				title: '处理评论信息',
				area: ['500px', '500px'],
				maxmin: true,
				btn:['提交评论'],
				content: $("#seeBox").html(),
				yes: function() {
					if($("#neweval").val()!=''){
						var thisjson = {"id": data.id,
			                "evaluateId": data.evaluateId,
			                "commodityNumber":'',
			                "evaluateRelpyText":'',
			                
			                "newevaluate":$("#neweval").val()
				            }
						AjaxPostFn('system/orderinfo/evaluate/reply/insert',JSON.stringify(thisjson),function(result){
							console.log(result)
						})
					}
				
				},
				success: function(layero) {
					 $.getJSON(AllUrl+"api/bizcommodity/selectbynumber?adcode=100000&commoditynumber="+data.commodityNumber,function(result){
					 	if(result.htmlState.status == 200){
					 		
					 		if(result.htmlState.error){
					 			$(".comdet").html('<b>当前商品已下架或未销售</b>');
					 		}else{
					 			var ResultObj = result.dataResultObj ; 
					 			$(".comdet").html('<b>'+ResultObj.title+'</b>');
					 		
					 		}
					 		
					 	}
					 	console.log(result)
					  });
					
				}
			});

		} else if(obj.event === 'delthis') {
			layer.confirm('是否删除该条信息', function(index) {
				AjaxPostFn('system/orderinfo/evaluate/delete', '{"evaluateId": "' + data.evaluateId + '"}', function(data) {
					if(data.htmlState.status == 200) {
						layer.msg("删除成功");
						obj.del();
					} else {
						layer.msg(jsonData.htmlState.message);
					}
				}, obj);

				//删除相应的库存
				layer.close(index);
			});

		}
	})
})